```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>堆排序算法详解 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background: #2d3748;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        .code-block:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
        }
        .animate-float {
            animation: float 6s ease-in-out infinite;
        }
        @keyframes float {
            0% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
            100% { transform: translateY(0px); }
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        .custom-list li {
            position: relative;
            padding-left: 1.5rem;
            margin-bottom: 0.75rem;
        }
        .custom-list li:before {
            content: "";
            position: absolute;
            left: 0;
            top: 0.5rem;
            width: 0.5rem;
            height: 0.5rem;
            background-color: #667eea;
            border-radius: 50%;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl flex flex-col md:flex-row items-center">
            <div class="md:w-1/2 mb-10 md:mb-0">
                <h1 class="text-4xl md:text-5xl font-bold mb-4 leading-tight">深入理解堆排序算法</h1>
                <p class="text-xl mb-8 opacity-90">一种基于完全二叉树的高效排序方法</p>
                <div class="flex items-center">
                    <div class="bg-white bg-opacity-20 rounded-full p-2 mr-4">
                        <i class="fas fa-code text-white text-xl"></i>
                    </div>
                    <p class="text-sm opacity-80">时间复杂度: O(n log n)</p>
                </div>
            </div>
            <div class="md:w-1/2 flex justify-center">
                <div class="relative w-64 h-64">
                    <div class="absolute inset-0 bg-white bg-opacity-10 rounded-full filter blur-md animate-float"></div>
                    <div class="relative z-10 w-full h-full flex items-center justify-center">
                        <div class="mermaid" style="width: 100%; height: 100%">
                            graph TD
                                A[堆排序] --> B[构建最大堆]
                                A --> C[排序过程]
                                B --> D[从最后一个非叶子节点开始]
                                B --> E[自下而上堆化]
                                C --> F[交换堆顶与末尾元素]
                                C --> G[缩小堆范围并堆化]
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl py-12 px-4 md:px-0">
        <!-- Overview Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-6 md:p-8">
                    <h2 class="text-2xl font-bold mb-4 text-gray-800 border-b pb-2">算法概述</h2>
                    <p class="text-gray-700 mb-6">堆排序(Heap Sort)是一种基于堆数据结构的排序算法，利用堆的特性实现高效排序。它是一种不稳定的排序算法，时间复杂度为O(n log n)，且不需要额外的存储空间。</p>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="bg-blue-50 rounded-lg p-6">
                            <h3 class="font-semibold text-lg mb-3 text-blue-800 flex items-center">
                                <i class="fas fa-check-circle mr-2"></i> 优点
                            </h3>
                            <ul class="custom-list text-blue-900">
                                <li>时间复杂度为O(n log n)，效率较高</li>
                                <li>原地排序，空间复杂度O(1)</li>
                                <li>适用于大数据量排序</li>
                            </ul>
                        </div>
                        <div class="bg-red-50 rounded-lg p-6">
                            <h3 class="font-semibold text-lg mb-3 text-red-800 flex items-center">
                                <i class="fas fa-exclamation-circle mr-2"></i> 缺点
                            </h3>
                            <ul class="custom-list text-red-900">
                                <li>不稳定排序算法</li>
                                <li>实现相对复杂</li>
                                <li>缓存不友好</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Working Principle -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 text-center">堆排序工作原理</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- Heap Concept -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6 md:p-8">
                        <div class="flex items-center mb-4">
                            <div class="bg-blue-100 p-2 rounded-full mr-4">
                                <i class="fas fa-project-diagram text-blue-600"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">堆的概念</h3>
                        </div>
                        <p class="text-gray-700 mb-4">堆是一种完全二叉树结构，满足堆性质：</p>
                        <ul class="custom-list text-gray-700">
                            <li>最大堆：每个节点的值都大于或等于其子节点的值</li>
                            <li>最小堆：每个节点的值都小于或等于其子节点的值</li>
                        </ul>
                        <div class="mt-6">
                            <div class="mermaid">
                                graph TD
                                    A[7] --> B[5]
                                    A --> C[6]
                                    B --> D[3]
                                    B --> E[4]
                                    C --> F[1]
                                    C --> G[2]
                            </div>
                            <p class="text-sm text-gray-500 mt-2 text-center">最大堆示例</p>
                        </div>
                    </div>
                </div>

                <!-- Algorithm Steps -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6 md:p-8">
                        <div class="flex items-center mb-4">
                            <div class="bg-purple-100 p-2 rounded-full mr-4">
                                <i class="fas fa-sort-amount-down text-purple-600"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">算法步骤</h3>
                        </div>
                        <ol class="list-decimal pl-5 space-y-3 text-gray-700">
                            <li><strong>构建最大堆</strong>：将无序数组构建成最大堆，从最后一个非叶子节点开始堆化</li>
                            <li><strong>排序过程</strong>：将堆顶元素与末尾元素交换，缩小堆范围并重新堆化</li>
                            <li><strong>重复</strong>：直到堆的大小为1，数组有序</li>
                        </ol>
                        <div class="mt-6 bg-yellow-50 p-4 rounded-lg border border-yellow-200">
                            <h4 class="font-medium text-yellow-800 mb-2 flex items-center">
                                <i class="fas fa-lightbulb mr-2"></i> 关键点
                            </h4>
                            <p class="text-yellow-700 text-sm">堆排序的关键在于维护堆性质，每次都能快速提取最大/最小元素</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Detailed Steps -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-6 md:p-8">
                    <h2 class="text-2xl font-bold mb-6 text-gray-800 border-b pb-2">详细步骤解析</h2>
                    
                    <!-- Build Max Heap -->
                    <div class="mb-8">
                        <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                            <span class="bg-blue-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">1</span>
                            构建最大堆
                        </h3>
                        <div class="pl-11">
                            <p class="text-gray-700 mb-4">从数组的最后一个非叶子节点开始，向前调整每个节点。对于索引i的节点：</p>
                            <ul class="custom-list text-gray-700 mb-4">
                                <li>左子节点在2*i + 1位置</li>
                                <li>右子节点在2*i + 2位置</li>
                                <li>比较节点与子节点，确保根节点是最大值</li>
                                <li>如果不满足则交换并递归堆化受影响的子树</li>
                            </ul>
                            <div class="bg-gray-100 p-4 rounded-lg mb-4">
                                <p class="font-mono text-sm text-gray-800">// 最后一个非叶子节点索引 = n/2 - 1</p>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Sorting Process -->
                    <div>
                        <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                            <span class="bg-purple-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">2</span>
                            排序过程
                        </h3>
                        <div class="pl-11">
                            <p class="text-gray-700 mb-4">将最大堆转换为有序数组：</p>
                            <ul class="custom-list text-gray-700">
                                <li>交换堆顶(最大值)与当前末尾元素</li>
                                <li>减小堆范围(排除已排序元素)</li>
                                <li>对新堆顶进行堆化操作</li>
                                <li>重复直到堆大小为1</li>
                            </ul>
                            <div class="mt-6 grid md:grid-cols-2 gap-4">
                                <div class="bg-green-50 p-4 rounded-lg border border-green-200">
                                    <h4 class="font-medium text-green-800 mb-2">初始堆</h4>
                                    <div class="mermaid text-xs">
                                        graph TD
                                            7 --> 5
                                            7 --> 6
                                            5 --> 3
                                            5 --> 4
                                            6 --> 1
                                            6 --> 2
                                    </div>
                                </div>
                                <div class="bg-indigo-50 p-4 rounded-lg border border-indigo-200">
                                    <h4 class="font-medium text-indigo-800 mb-2">排序过程</h4>
                                    <div class="mermaid text-xs">
                                        graph TD
                                            A[交换7和2] --> B[堆化]
                                            B --> C[6]
                                            C --> D[5]
                                            C --> E[2]
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Code Example -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 text-center">代码实现示例</h2>
            
            <div class="code-block overflow-hidden">
                <div class="flex items-center bg-gray-800 px-4 py-2">
                    <div class="flex space-x-2 mr-4">
                        <span class="w-3 h-3 rounded-full bg-red-500"></span>
                        <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
                        <span class="w-3 h-3 rounded-full bg-green-500"></span>
                    </div>
                    <p class="text-gray-400 text-sm">HeapSortDemo.java</p>
                </div>
                <pre class="text-gray-300 p-4 overflow-x-auto"><code>
public class HeapSortDemo {

    // 主函数：堆排序
    public static void heapSort(int[] arr) {
        int n = arr.length;

        // 构建最大堆
        for (int i = n / 2 - 1; i >= 0; i--) {
            heapify(arr, n, i);
        }

        // 一个一个从堆中取出元素
        for (int i = n - 1; i > 0; i--) {
            // 当前根节点与最后一个节点交换
            swap(arr, 0, i);

            // 重新堆化根节点
            heapify(arr, i, 0);
        }
    }

    // 堆化操作
    private static void heapify(int[] arr, int n, int i) {
        int largest = i; // 初始化最大元素为根节点
        int left = 2 * i + 1; // 左子节点
        int right = 2 * i + 2; // 右子节点

        // 如果左子节点比根节点大
        if (left < n && arr[left] > arr[largest]) {
            largest = left;
        }

        // 如果右子节点比根节点大
        if (right < n && arr[right] > arr[largest]) {
            largest = right;
        }

        // 如果最大元素不是根节点
        if (largest != i) {
            swap(arr, i, largest);

            // 递归堆化受影响的子树
            heapify(arr, n, largest);
        }
    }

    // 交换两个元素
    private static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    // 主函数：测试堆排序
    public static void main(String[] args) {
        int[] arr = {12, 11, 13, 5, 6, 7};
        heapSort(arr);
        System.out.println("排序后的数组：");
        for (int num : arr) {
            System.out.print(num + " ");
        }
    }
}
                </code></pre>
            </div>
            
            <div class="mt-6 grid md:grid-cols-2 gap-6">
                <div class="bg-white p-6 rounded-lg shadow-md card-hover">
                    <h3 class="font-semibold text-lg mb-3 text-gray-800 flex items-center">
                        <i class="fas fa-code-branch mr-2 text-blue-600"></i> 代码解析
                    </h3>
                    <ul class="custom-list text-gray-700">
                        <li><code>heapSort()</code> 是主排序方法，负责构建堆和排序过程</li>
                        <li><code>heapify()</code> 维护堆性质的核心方法</li>
                        <li><code>swap()</code> 辅助方法用于交换数组元素</li>
                        <li>主函数演示了如何使用堆排序</li>
                    </ul>
                </div>
                <div class="bg-white p-6 rounded-lg shadow-md card-hover">
                    <h3 class="font-semibold text-lg mb-3 text-gray-800 flex items-center">
                        <i class="fas fa-chart-line mr-2 text-purple-600"></i> 性能分析
                    </h3>
                    <ul class="custom-list text-gray-700">
                        <li>构建堆的时间复杂度: O(n)</li>
                        <li>每次堆化时间复杂度: O(log n)</li>
                        <li>总时间复杂度: O(n log n)</li>
                        <li>空间复杂度: O(1)</li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Comparison Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 text-center">与其他排序算法比较</h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="p-6 md:p-8">
                    <div class="overflow-x-auto">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">算法</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">时间复杂度</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">空间复杂度</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">稳定性</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">适用场景</th>
                                </tr>
                            </thead>
                            <tbody class="bg-white divide-y divide-gray-200">
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap font-medium text-gray-900">堆排序</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-gray-500">O(n log n)</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-gray-500">O(1)</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-gray-500">不稳定</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-gray-500">大数据量，内存受限</td>
                                </tr>
                                <tr class="bg-gray-50">
                                    <td class="px-6 py-4 whitespace-nowrap font-medium text-gray-900">快速排序</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-gray-500">O(n log n) 平均</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-gray-500">O(log n)</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-gray-500">不稳定</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-gray-500">通用排序</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap font-medium text-gray-900">归并排序</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-gray-500">O(n log n)</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-gray-500">O(n)</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-gray-500">稳定</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-gray-500">需要稳定性</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-400 py-10">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-white text-lg font-medium mb-1">技术小馆</h3>
                    <p class="text-sm">探索计算机科学的奥秘</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="hover:text-white transition-colors duration-300 text-sm">
                        <i class="fas fa-external-link-alt mr-1"></i> http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-sm">
                <p>© 2023 技术小馆. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```